package cn.biplam.front.component.view.systemManage.sysprivi.privilege.manage;

import cn.biplam.common.ajxcode.SystemCode.PriviDeployCode;
import cn.biplam.common.client.DataFilter;
import cn.biplam.common.client.Operator;
import cn.biplam.common.client.OperatorResult;
import cn.biplam.common.opcode.SysManageCode.PriviDeployOptCode;
import cn.biplam.common.struc.SysStruc.PriviDeployStruc;
import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.component.ComponentBase;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.template.control.Panel;

/**
 *  权限管理主页面
 * @author XiaoRuxing Dec 7, 20095:47:58 PM
 * @version 1.0
 */
public class PriviManageMain extends ComponentBase{
	
	private static String cId = PriviDeployCode.cId;
	
	public PriviManageMain(UserInfo user, String homeUrl, String recordId,
			KvMap<String, String> params) {
		super(user, homeUrl, recordId, params);
	}
	
	/**
	 * @return 权限管理
	 */
	public HtmlWindow get() throws ErrorMessage{
		Panel panel = new Panel(cId+"panel");
		setPanelContent(panel);
		return panel.get();
	}
	
	/**
	 *  放入权限管理选项卡内容,每个选项为一个权限大类
	 */
	private void setPanelContent(Panel panel) throws ErrorMessage{
		//获取所有权限大类
		OperatorResult result = Operator.get(PriviDeployOptCode.Query_All, 
				mUser.getUserID(), 
				new DataFilter());
		
		if(TOOLS.exist(result)){
			String priviName;
			String priviAction;
			String priviRootId;
			boolean isDefault = false;
			int i = 0;
			do{
				if(i==0){//设置默认选择第一个选项
					isDefault = true;
				}else{
					isDefault = false;
				}
				//放入权限大类到选项卡
				priviName = result.getValue(PriviDeployStruc.NAME);//选项名称
				priviAction = result.getValue(PriviDeployStruc.SHOW_ACT_ID);//选项跳转AjxId
				priviRootId = result.getValue(PriviDeployStruc.VIRTUAL_ROOT_ID);//选项ID为当前选择类型子树的根节点ID
				panel.put(priviName, priviAction, priviRootId,isDefault);
				i++;
			}while(result.next());
		}
	}
}
